package org.applesline.desensitize.handle.impl;

import org.applesline.desensitize.constants.DesensitizeType;
import org.applesline.desensitize.handle.DesensitizeAdapter;
import org.springframework.stereotype.Component;

/**
 * @author liuyaping
 * @date 2022/1/19
 */
@Component
public class IpHandler extends DesensitizeAdapter {

    @Override
    public String doMask(String ip) {
        if (isBlank(ip)) {
            return "";
        }
        int max = 6;
        return ip.length() <= max ? hide(ip, ip.length() - 1, ip.length()) : hide(ip, ip.length() - max, ip.length());
    }

    @Override
    public DesensitizeType getFieldType() {
        return DesensitizeType.IP;
    }
}
